import { createSlice } from '@reduxjs/toolkit'

const loadingStore = createSlice({
  name: 'loading',
  initialState: {
    isLoading: false
  },
  reducers: {
    openLoading(state) {
      state.isLoading = true
    },
    closeLoading(state) {
      state.isLoading = false
    }
  },
})

// 导出isLoading的ts类型
export type LoadingState = ReturnType<typeof loadingStore.reducer>

// 解构出actionCreater函数
export const { openLoading, closeLoading } = loadingStore.actions

// 导出reducer
export default loadingStore.reducer